package com.ars.common.service;

import com.ars.common.dao.userInformation;
import com.ars.common.beans.User.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

@WebServlet("/UserInfo")
public class userInfo extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response); // 复用处理逻辑
    }

    private void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        userInformation uif = new userInformation();
        try {
            ArrayList<User> userInformation = uif.getUserInformation();
            request.setAttribute("userInfo", userInformation); // 将数据封装成userInfo
            System.out.println("UserInfoTest");
            request.getRequestDispatcher("/admin/userInfo.jsp").forward(request, response); // 转发
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}

